﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Linq;

using Pg.BioMedics.SDR.Services;
using Pg.BioMedics.SDR.Entities.Codes;

namespace Pg.BioMedics.Web.Security
{
    /// <summary>
    /// SDR custome role provider
    /// </summary>
    public class LocalRoleProvider : RoleProvider
    {
        #region Overriden properties

        public override string ApplicationName
        {
            get
            {
                return "SDRWeb";
            }

            set { }
        }

        #endregion

        #region Overriden methods

        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override void CreateRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            throw new NotImplementedException();
        }

        public override string[] FindUsersInRole(string roleName, string usernameToMatch)
        {
            throw new NotImplementedException();
        }

        public override string[] GetAllRoles()
        {
            return new[] { RoleCodes.Administrator, RoleCodes.Operational, RoleCodes.ExternalOperational };
        }

        public override string[] GetRolesForUser(string username)
        {
            ISecurityService securityService = ServiceFactory.SecurityService;
            return securityService.GetRolesForPerson(username);
        }

        public override string[] GetUsersInRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override bool IsUserInRole(string username, string roleName)
        {
            throw new NotImplementedException();
        }

        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override bool RoleExists(string roleName)
        {
            return GetAllRoles().Contains(roleName);
        }

        #endregion
    }
}
